package com.xykj.enterprise.wechat.event.proc.sync;

import com.alibaba.fastjson.JSONObject;
import com.xykj.enterprise.wechat.bean.ext.externalcontact.GetCorpTagListVo;
import com.xykj.enterprise.wechat.event.service.CorpTagService;
import com.xykj.enterprise.wechat.event.service.ext.ExternalContactService;
import com.ydn.its.ItsProc;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;

/**
 * 同步企业标签
 *
 * @Author zhouxu
 * @create 2021-04-12 10:45
 */
@Slf4j
public class SyncCorpTagProc implements ItsProc {

    @Autowired
    private CorpTagService corpTagService;
    @Autowired
    private ExternalContactService externalContactService;


    @Override
    public void execute(String message) throws Exception {

        JSONObject jsonObject = JSONObject.parseObject(message);
        String accessToken = jsonObject.getString("access_token");
        String corpid = jsonObject.getString("corpid");

        // 1.查询企业标签
        GetCorpTagListVo listVo = externalContactService.getCorpTagList(accessToken, null, null);
        // 2.同步数据
        corpTagService.syncCorpTag(listVo, corpid);
    }
}
